<template>
  <div class="help">
    <div class="header">
      <van-nav-bar left-arrow @click-left="onClickLeft" />
      <h1>专业管家为您找房</h1>
      <p>海量真房源/租金可月付/租期有保障</p>
    </div>

    <div class="main">
      <div class="type">
        <p>您想的房源类型是?</p>
        <span
          v-for="(item, index) in houseList"
          :key="index"
          :class="{ active: index === houseactive }"
          @click="houseactive = index"
        >
          {{ item }}
        </span>
      </div>

      <div class="live">
        <p>您想要住的地区是?(必填)</p>
        <div>
          <van-field
            v-model="state.fieldValue"
            is-link
            readonly
            placeholder="必选"
            @click="state.show = true"
          />
          <van-popup v-model:show="state.show" round position="bottom">
            <van-cascader
              v-model="state.cascaderValue"
              title="您想要住的地区是"
              :options="options"
              @close="state.show = false"
              @finish="onFinish"
            />
          </van-popup>
        </div>
      </div>

      <div class="company">
        <p>您的公司地址在哪?(必填)</p>
        <div>
          <van-field
            v-model="state.fieldValue1"
            is-link
            readonly
            placeholder="必选"
            @click="state.show1 = true"
          />
          <van-popup v-model:show="state.show1" round position="bottom">
            <van-cascader
              v-model="state.cascaderValue1"
              title="您想要住的地区是"
              :options="options1"
              @close="state.show1 = false"
              @finish="onFinish1"
            />
          </van-popup>
        </div>
      </div>

      <div class="price">
        <p>您的租房预算是多少?</p>
        <ul>
          <li
            v-for="(item, index) in priceList"
            :key="index"
            :class="{ active: index === priceactive }"
            @click="priceactive = index"
          >
            {{ item }}
          </li>
        </ul>
      </div>
    </div>

    <div class="btn">
      <van-button color="#FFAC42" type="primary" @click="goConsult"
        ><p>咨询管家</p>
        <p class="font10">在线沟通 专人答疑</p></van-button
      >
      <van-button color="#FF3D37"
        ><p>提交需求</p>
        <p class="font10">省心力荐 最高效</p></van-button
      >
    </div>
  </div>
</template>

<script>
// import { Toast } from "vant";
import { reactive } from "vue";

export default {
  methods: {
    onClickLeft() {
      //点击跳转至上次浏览页面
      // this.$router.go(-1)

      //指定跳转地址
      this.$router.push("/home");
    },
    goConsult() {
      this.$router.push("/consult");
    },
  },
  data() {
    return {
      houseList: ["不限", "整租", "合租"],
      priceList: [
        "不限",
        "1500元以下",
        "1500-2000元",
        "2000-3000元",
        "3000-4000元",
        "4000-5000元",
        "5000元以上",
      ],
      houseactive: 0,
      priceactive: 0,
    };
  },
  setup() {
    // const onClickLeft = () => Toast("返回");
    const state = reactive({
      show: false,
      fieldValue: "",
      cascaderValue: "",
      show1: false,
      fieldValue1: "",
      cascaderValue1: "",
    });

    // 选项列表，children 代表子选项，支持多级嵌套
    const options = [
      {
        text: "浙江省",
        value: "330000",
        children: [
          {
            text: "杭州市",
            value: "330100",
            children: [
              {
                text: "上城区",
                value: "330101",
              },
              {
                text: "萧山区",
                value: "330102",
              },
              {
                text: "拱墅区",
                value: "330103",
              },
              {
                text: "滨江区",
                value: "330104",
              },
              {
                text: "江干区",
                value: "330105",
              },
            ],
          },
        ],
      },
      {
        text: "江苏省",
        value: "320000",
        children: [
          {
            text: "南京市",
            value: "320100",
            children: [
              {
                text: "建邺区",
                value: "320101",
              },
              {
                text: "鼓楼区",
                value: "320102",
              },
              {
                text: "雨花台区",
                value: "320103",
              },
              {
                text: "江宁区",
                value: "320104",
              },
            ],
          },
          {
            text: "常州市",
            value: "320200",
            children: [
              {
                text: "新北区",
                value: "330201",
              },
              {
                text: "武进区",
                value: "330201",
              },
              {
                text: "钟楼区",
                value: "330201",
              },
              {
                text: "天宁区",
                value: "330201",
              },
            ],
          },
        ],
      },
    ];
    const options1 = [
      {
        text: "浙江省",
        value: "330000",
        children: [
          {
            text: "杭州市",
            value: "330100",
            children: [
              {
                text: "上城区",
                value: "330101",
              },
              {
                text: "萧山区",
                value: "330102",
              },
              {
                text: "拱墅区",
                value: "330103",
              },
              {
                text: "滨江区",
                value: "330104",
              },
              {
                text: "江干区",
                value: "330105",
              },
            ],
          },
        ],
      },
      {
        text: "江苏省",
        value: "320000",
        children: [
          {
            text: "南京市",
            value: "320100",
            children: [
              {
                text: "建邺区",
                value: "330201",
              },
              {
                text: "鼓楼区",
                value: "330201",
              },
              {
                text: "雨花台区",
                value: "330201",
              },
              {
                text: "江宁区",
                value: "330201",
              },
            ],
          },
          {
            text: "常州市",
            value: "320200",
            children: [
              {
                text: "新北区",
                value: "330201",
              },
              {
                text: "武进区",
                value: "330202",
              },
              {
                text: "钟楼区",
                value: "330203",
              },
              {
                text: "天宁区",
                value: "330204",
              },
            ],
          },
        ],
      },
    ];
    // 全部选项选择完毕后，会触发 finish 事件
    const onFinish = ({ selectedOptions }) => {
      state.show = false;
      state.fieldValue = selectedOptions.map((option) => option.text).join("/");
    };
    const onFinish1 = ({ selectedOptions }) => {
      state.show1 = false;
      state.fieldValue1 = selectedOptions
        .map((option) => option.text)
        .join("/");
    };
    return {
      // onClickLeft,
      state,
      options,
      onFinish,
      options1,
      onFinish1,
    };
  },
};
</script>

<style lang="less">
.help {
  .header {
    position: relative;
    .van-nav-bar__left {
      .van-icon {
        color: #fff;
        font-size: 20px;
      }
    }

    .van-nav-bar__text {
      display: block;
      font-size: 30px;
      color: #fff;
    }
    h1 {
      position: absolute;
      left: 35px;
      top: 96px;
      z-index: 100;
      font-size: 23px;
      font-weight: 500;
      color: #fff;
    }
    p {
      position: absolute;
      left: 35px;
      top: 123px;
      z-index: 100;
      font-size: 12px;
      font-weight: 500;
      color: #fff;
    }
  }
  .van-nav-bar {
    height: 160px;
    width: 100%;
    background-image: url("../assets/img/help-01.png");
    background-size: 375px 160px;
    // background-color: red;
  }
  .main {
    background-color: #fff;
    width: 345px;
    margin: auto;
    padding: 0 7px 0 7px;
    .type {
      p {
        width: 140px;
        height: 15px;
        font-size: 16px;
        font-family: PingFang SC;
        font-weight: bold;
        color: #2e2e2e;
        padding: 34px 0 25px;
      }
      span {
        display: inline-block;
        width: 95px;
        height: 31px;
        line-height: 31px;
        border-radius: 2px;
        font-size: 12px;
        font-family: PingFang SC;
        font-weight: 500;
        text-align: center;
        margin-left: 11px;
      }
      .active {
        background-color: #ffeff2;
        color: #e75166;
      }
    }
    .live {
      p {
        margin-top: 39px;
        width: 193px;
        height: 16px;
        font-size: 16px;
        font-family: PingFang SC;
        font-weight: bold;
        color: #2e2e2e;
      }
      div {
        .van-cell {
          margin-top: 10px;
        }
      }
    }
    .company {
      p {
        margin-top: 39px;
        width: 193px;
        // height: 16px;
        font-size: 16px;
        font-family: PingFang SC;
        font-weight: bold;
        color: #2e2e2e;
      }
    }
    .price {
      padding-bottom: 31px;
      p {
        margin-top: 39px;
        width: 193px;
        height: 16px;
        font-size: 16px;
        font-family: PingFang SC;
        font-weight: bold;
        color: #2e2e2e;
      }
      ul {
        display: flex;
        flex-wrap: wrap;
        text-align: center;

        li {
          width: 95px;
          height: 31px;
          line-height: 31px;
          background: #f8f8f8;
          border-radius: 2px;
          font-size: 12px;
          margin-top: 14px;
          margin-left: 10px;
        }
        .active {
          background: #ffeff2;
          color: #e75166;
        }
      }
    }
  }
  .btn {
    width: 345px;
    margin: auto;
    display: flex;
    justify-content: space-between;
    margin-top: 26px;

    p {
      font-size: 15px;
      font-family: PingFang SC;
      font-weight: 500;
      color: #ffffff;
    }
    .font10 {
      font-size: 10px;
      font-family: PingFang SC;
      font-weight: 500;
      color: #ffffff;
    }

    button {
      width: 165px;
      height: 57px;
      border-radius: 5px;
    }
  }
}
</style>
